#include<stdio.h>
int days(int year,int month)
{
	switch( month)
	{
		case 1: 
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12: return 31;
		case 4:
		case 6:
		case 9:
		case 11: return 30;
		case 2:{	if(year%400==0) return 29;
			       else if(year%100==0) return 28;
			       else if(year%4==0) return 29;
			       else return 28;
		       }
	}
}


int main()
{
	int year=0;
	int month=0;
	scanf("%d%d",&year,&month);
	if(year>=3000 || year<=1000)
	{
		printf("invalid year!");
	}
	else if(month<=0 || month>=13)
	{
		printf("invalid month!");
	}
	else
	{
	int s=0;
	s=days(year,month);

	printf("%d",s);
	}

	return 0;
}



